﻿package main

import (
   //"fmt"
   "strings"
   //"encoding/json"
)

var origStr string = "{appId=wx979a17eece0bcf22, timeStamp=1566554146, nonceStr=375b84baff614ffebb3eae65a45cdf5d, package=prepay_id=wx2317554690691935e6a1c2381901198200, signType=RSA, paySign=stBP2RrSq5tsNWBqBWveYGN4bzdGRV8r8YLVijJs9kwN/ijPfdr1x/qLttAcmA+FwnhTFd1oYRb8pyxQuPrhFEBsxPGQaNAms/rSVNLzz6N+oyIsFOXoOBlSLOTnUVQ60qQA3TNkT3X24kWaOEf8oZj44Lq7CStTR/75PcLFY9p053tLfySEyx3DUCYSIzkoGDwTNmxvsEqUkNUqh9sBvXyzcUcaaXkSQHICGq39kz5dhWaXtd5gU838juHI/UPJ7xw62UDtVKFPOn1pe0RGyhk/RbZOTQgTTmvfeer9Y/Yv5Q+FmEjD7iPuEVtxb1qE2+st9MBIvgYmVNWV0RCJWA==}"


type PayInfo struct {
	Package   string   `json:"package"`
	AppId     string   `json:"appId"`
	NonceStr  string   `json:"nonceStr"`
	TimeStamp string   `json:"timeStamp"`
	SignType  string   `json:"signType"`
	PaySign   string   `json:"paySign"`
}

func ParsePayRsp(str string) *PayInfo {
	var rspInfo PayInfo
	str = strings.TrimPrefix(str, "{")
	str = strings.TrimSuffix(str, "}")
	valueArr := strings.Split(str, ",")
	for _, v := range valueArr {
	    if ok := strings.Contains(v, "appId"); ok {   
		   pos := strings.Index(v, "=")
	       if pos != -1 {
			  rspInfo.AppId = v[pos+1:]	
		   }
		}	
		if ok := strings.Contains(v, "timeStamp"); ok {   
		   pos := strings.Index(v, "=")
	       if pos != -1 {
			  rspInfo.TimeStamp = v[pos+1:]	
		   }
		}
		if ok := strings.Contains(v, "nonceStr"); ok {   
		   pos := strings.Index(v, "=")
	       if pos != -1 {
			  rspInfo.NonceStr = v[pos+1:]	
		   }	   
		}
		if ok := strings.Contains(v, "package"); ok {   
		   pos := strings.Index(v, "=")
	       if pos != -1 {
			  rspInfo.Package = v[pos+1:]	
		   }	   
		}
		if ok := strings.Contains(v, "signType"); ok {   
		   pos := strings.Index(v, "=")
	       if pos != -1 {
			  rspInfo.SignType = v[pos+1:]	
		   }		   
		}
		if ok := strings.Contains(v, "paySign"); ok {   
		   pos := strings.Index(v, "=")
	       if pos != -1 {
			  rspInfo.PaySign = v[pos+1:]
		   }	   
		}
	}
    return &rspInfo	
}


func main() {
    //microApp()
	//refund()
	//payRsp := ParsePayRsp(origStr)
    //wxRspJson, _:= json.Marshal(payRsp)
    //fmt.Println("wxRspJson:", string(wxRspJson))	
	notifyDemo()
}
